package com.hengxinguotong.zhihuichengjian.treeview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.List;

/**
 * @CopyRight 恒信国通信息科技
 * @Author wulei
 * @Date 2018/8/21
 */

public abstract class RecyclerAdapter<K, T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> {
    protected Context context;
    protected List<K> dataList;
    protected OnItemClickListener onItemClickListener;
    protected OnClickListener onClickListener;
    protected ClickListener clickListener;

    public RecyclerAdapter(Context context, List<K> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    public void setDataList(List<K> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public void setClickListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public int getItemCount() {
        if(dataList != null){
            return dataList.size();
        }
        return 0;
    }

    public static abstract class BaseViewHolder<W> extends RecyclerView.ViewHolder{

        public View itemView;

        public BaseViewHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
        }

        public abstract void bindData(int position);
    }

    public interface OnClickListener<K>{
        void onClick(K k);
    }

    public interface ClickListener{
        void onClick(int position);
    }

    public interface OnItemClickListener<K> {
        void onItemClick(View view, K k, int position);
    }
}
